const fs = require("fs");
// console.log(fs);

// fs.writeFile("./fs-test.js", "hello world", err => {
//     console.log(err);
// })

// fs.writeFile("./main.txt", "hello world", err => {
//     console.log(err);
// })


try{
    fs.writeFileSync("./main.txt", "surprise")
}catch(err){
    console.log(err)
}

let data;
try{
    data = fs.readFileSync("./main.txt","utf-8");
}catch(add){
    console.log(add)
}

const str = data + "mother fucter";
try{
    fs.writeFileSync("./main.txt", fs.readFileSync("./main.txt","utf-8") + " motherfucker")
}catch(err){
    console.log(err)
}


const qs = require("querystring");
function parse(str){
    const obj = {};
    str.split("&").forEach(val => {
        obj[val.split('=')[0] = val.split('=')[1]];
    });
    return obj;
}
console.log(parse(str))

const o = {a:1,b:2,c:3}

function stringify(o){
    let s ="";
    for(let i in o){
        s += `${i} = ${o[i]}&`
    }
    return s.slice(0,-1);
}
console.log(stringify(o))